package main

import "fmt"

//对称生成:8ms 85%,6.5MB 91%
func grayCode(n int) []int {
	ans := []int{0, 1}
	for i := 1; i < n; i++ {
		sLen := len(ans)
		for j := sLen - 1; j >= 0; j-- {
			ans = append(ans, ans[j]+1<<i)
		}
	}
	return ans
}

func main() {
	fmt.Println(grayCode(2))
}
